package app.web.admin.domain.pojo;

import app.core.ar.Ar;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.feizns.quickstart.ddl.annotation.Comment;
import com.gitee.feizns.quickstart.domain.Types;
import com.gitee.feizns.quickstart.domain.query.Relationship;
import com.mybatisflex.core.handler.JacksonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.List;

/**
 * 管理员
 * @author feizns
 * @since 2025/3/11
 */
@Data
@Entity
@Comment("管理员")
@EqualsAndHashCode(callSuper = true)
@Table(name = "admin")
@com.mybatisflex.annotation.Table(value = "admin", comment = "管理员")
public class Admin extends Ar<Admin> {

    /**
     * 超管理编号
     */
    public static final Long SuperAdminId = 1L;

    /**
     * 用户名称
     */
    @Comment("用户名称")
    private String name;

    /**
     * 头像
     */
    @Comment("头像")
    private String avatar;

    /**
     * 手机号码
     */
    @Comment("手机号码")
    @Column(unique = true)
    private String mobile;

    /**
     * 职位
     */
    @Comment("职位")
    private String title;

    /**
     * 邮箱
     */
    @Comment("邮箱")
    @Column(unique = true)
    private String email;

    /**
     * 密码
     */
    @JsonIgnore
    @Comment("密码")
    @Column(columnDefinition = "VARCHAR(255) DEFAULT '123456'")
    private String password;

    /**
     * 角色编号列表
     */
    @Type(type = Types.JSON)
    @Column(columnDefinition = Types.JSON)
    @Comment("角色编号列表")
    @com.mybatisflex.annotation.Column(typeHandler = JacksonTypeHandler.class)
    private List<Long> roleIds;

    /**
     * @return {@link Relationship }<{@link AdminOfRole }, {@link Long }, {@link Long }>
     */
    public Relationship<AdminOfRole, Long, Long> relationshipOfAdminOfRole() {
        return Relationship.of(AdminOfRole::getAdminId, getId(), AdminOfRole::getRoleId);
    }

}
